import { jsonToPath } from "@/utils/common";
import request from "@/utils/request";
import type { BasePageReq } from "../../baseType";
import type {
  TrademarkDataResp,
  TrademarkListResp,
  TrademarkPageResp,
  TrademarkData,
} from "./type";

enum TRADEMARK_API {
  TRADEMARK_LIST_ALL = "/admin/product/baseTrademark/getTrademarkList",
  TRADEMARK_PAGE = "/admin/product/baseTrademark",
  TRADEMARK_ADD = "/admin/product/baseTrademark/save",
  TRADEMARK_EDIT = "/admin/product/baseTrademark/update",
  TRADEMARK_DEL = "/admin/product/baseTrademark/remove",
  TRADEMARK_DETAIL = "/admin/product/baseTrademark/get",
  TRADEMARK_QUERY_COND = "/admin/product/baseTrademark/findBaseTrademarkByKeyword",
}

export const trademarkList = () => {
  return request.get<any, TrademarkListResp>(TRADEMARK_API.TRADEMARK_LIST_ALL);
};

export const trademarkPage = (data: BasePageReq) => {
  return request.get<any, TrademarkPageResp>(
    TRADEMARK_API.TRADEMARK_PAGE + jsonToPath(data),
  );
};
export const trademarkSaveOrUpdate = (data: TrademarkData) => {
  if (data.id) {
    return request.put<any, any>(TRADEMARK_API.TRADEMARK_EDIT, data);
  }
  return request.post<any, any>(TRADEMARK_API.TRADEMARK_ADD, data);
};
export const trademarkDel = (id: number) => {
  return request.delete<any, any>(TRADEMARK_API.TRADEMARK_DEL + `/${id}`);
};
export const trademarkDetail = (id: number) => {
  return request.get<any, TrademarkDataResp>(
    TRADEMARK_API.TRADEMARK_DETAIL + `/${id}`,
  );
};
export const trademarkQueryCond = (keyword: string) => {
  return request.get<any, TrademarkListResp>(
    TRADEMARK_API.TRADEMARK_QUERY_COND + `/${keyword}`,
  );
};
